package test01.yan.t5;

import java.io.RandomAccessFile;
import java.io.IOException;

public class ReverseFileOutput {
    public static void main(String[] args) {
        if (args.length != 1) {
            System.out.println("Usage: java ReverseFileOutput <filename>");
            return;
        }

        try (RandomAccessFile raf = new RandomAccessFile(args[0], "r")) {
            long fileLength = raf.length();
            for (long pos = fileLength - 1; pos >= 0; pos--) {
                raf.seek(pos);
                byte b = raf.readByte();
                System.out.write(b);
            }
            System.out.flush();
        } catch (IOException e) {
            System.err.println("Error reading or writing file: " + e.getMessage());
        }
    }
}
